import Vue from "vue"
import { formatDate } from "./vue-global"

export function formatMoney(value = "", key = "") {
	value += ""
	if (value == "null") {
		value = ""
	}
	const length = value.length
	if (length <= 3) {
		return value
	}
	const moreThanValue = length % 3 // 2 900 000
	let splitMoney = ""

	if (moreThanValue) {
		splitMoney = value.slice(0, moreThanValue) + ","
	}
	let match = value.slice(moreThanValue, length).match(/\d{3}/g)
	return key + splitMoney + (match ? match.join(",") : value)
}

Vue.filter("formatMoney", formatMoney)
Vue.filter("formatDate", formatDate)
